package com.example.demo;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.List;

public class RedisDemoString {

    public static void test(Jedis jedis) {
        //清空数据库
        jedis.flushAll();
        System.out.println("mset 和 mget 使用");
        jedis.mset("k1","111","k2","222","k3","333");
        List<String> mget = jedis.mget("k1", "k2", "k3","k4");
        System.out.println("mget: " +mget);

        System.out.println("getrange 和 setrange 使用");

        jedis.set("k4","abcdefgh");

        String k4 = jedis.getrange("k4", 0, 4);
        System.out.println("result: " +k4);

        jedis.setrange("k4",0,"eeee");
        System.out.println("k4: " +jedis.get("k4"));

        System.out.println("append 使用");
        jedis.append("k4","aaaaaa");
        System.out.println("k4: " + jedis.get("k4"));

        System.out.println("incr 和 decr 使用");

        jedis.set("k5","111");
        System.out.println( "k5: " + jedis.incr("k5"));
        System.out.println( "k5: " + jedis.decr("k5"));

    }
    public static void main(String[] args) {
        JedisPool jedisPool = new JedisPool("tcp://127.0.0.1:8888");
        try(Jedis jedis = jedisPool.getResource()) {
            test(jedis);
        }
    }
}
